//
//  MKUpDateCollectionViewCell.m
//  ManKeCartoon
//
//  Created by 邹功梁 on 15/10/23.
//  Copyright © 2015年 ManKe. All rights reserved.
//

#import "MKUpDateCollectionViewCell.h"
#import "MKBaseHeader.h"
@implementation MKUpDateCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _upDateDataArray = [[NSMutableArray alloc] init];
        
        _upDateTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _upDateTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _upDateTableView.dataSource = self;
        _upDateTableView.delegate = self;
        [self.contentView addSubview:_upDateTableView];
    }
    return self;
}


-(void)setUpDateDataArray:(NSMutableArray *)upDateDataArray{

    _upDateDataArray = [NSMutableArray arrayWithArray:upDateDataArray];
    [self.upDateTableView reloadData];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _upDateDataArray.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120 * HEIGHT;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"reuseIdentifier";
    MKUpDateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MKUpDateTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    MKUpDateModel *model = [_upDateDataArray objectAtIndex:indexPath.row];
    [cell setUpDateModel:model];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MKUpDateModel *upDateModel = [_upDateDataArray objectAtIndex:indexPath.row];
//    NSLog(@"%@", upDateModel.title);
    MKCartoonViewController *cartoon = [[MKCartoonViewController alloc] init];
    cartoon.comic_id = upDateModel.comic_id;
    // 封装的cell内push到 controller
    for (UIView* next = [self superview]; next; next = next.superview) {
        // 遍历找到全部响应者
        UIResponder* nextResponder = [next nextResponder];
        // 找到当前Controller响应者
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            
            UIViewController *controller = (UIViewController*)nextResponder ;
            [controller.navigationController pushViewController:cartoon animated:YES];
        }
    }
}
//- (void)setDelegate:(id<UITableViewDelegate>)delegate
//{
//    [self.upDateTableView setDelegate:delegate];
//}

@end
